#ifndef __ILISTENAPP_H__
#define __ILISTENAPP_H__

#include <iostream>
#include <functional>
#include <QObject>

#include "IVEFParser.h"
#include "ivefstreamhandler.h"
#include "IVEFObjectDatas.h"

typedef std::function<void(const ivef::LoginResponse&)> LoginResponseCallback;
typedef std::function<void(const ivef::ObjectDatas&)> ObjectDatasCallback;
typedef std::function<void(const ivef::Pong&)> PongCallback;

class QTimer;

class iListenApplication : public QObject {
    Q_OBJECT

public:
    iListenApplication();

    void setNetErrorCb(netErrorCallback cb);
    void setLoginResponseCb(LoginResponseCallback cb);
    void setObjectDatasCb(ObjectDatasCallback cb);
    void setPongCb(PongCallback cb);

    void StartPing(bool ping = true);

    void SendObjectDatas(const ivef::ObjectDatas &datas);

    void connectToServer(QString host, int port, QString user, QString password,
        QString logFileName="", bool slipstream=false, bool statistics=false);
private:
    ivef::Parser m_parser;
    IVEFStreamHandler *m_streamHandler;
    QString m_filter;

private slots:
    void handleMsgIvef( ivef::MSG_IVEF obj );
    void handleError( QString errorStr );

    void startConnect();
private:
    LoginResponseCallback m_login_response_cb;
    ObjectDatasCallback m_object_datas_cb;
    PongCallback m_pong_cb;

    QString m_host;
    int m_port;
    QString m_user;
    QString m_password;
    QString m_logFileName;
    bool m_slipstream;
    bool m_statistics;

    QTimer *m_ping_timer;
};

#endif
